<template>
	<!-- 金蝶管理 -->
	<div class="jindieWrapper">
		<div>
	     	<el-form :inline="true" :model="ruleForm" class="demo-form-inline">
	     		<el-form-item label="城市：">
	     		    <el-select v-model="ruleForm.cityCode" filterable >
	     		        <el-option v-for="item in citys"
	     		                   :key="item.cityId"
	     		                   :label="item.city"
	     		                   :value="item.cityId">
	     		        </el-option>
	     		    </el-select>
	     		</el-form-item>
	     		<el-form-item label="推送类型">
	     		  <el-select v-model="ruleForm.pushType">
	     		    <el-option label="全部" value=""></el-option>
	     		    <el-option v-for="item in typeList" :label="item.name" :value="item.id" :key="item.id"></el-option>
	     		  </el-select>
	     		</el-form-item>
				<el-form-item label="业务系统科目名称：">
					<el-select v-model="ruleForm.subjectCode">
						<el-option label="全部" value=""></el-option>
						<el-option v-for="item in subjectName" :label="item.name" :value="item.id" :key="item.id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="单据类型">
					<el-select v-model="ruleForm.billTypeCode">
						<el-option label="全部" value=""></el-option>
						<el-option v-for="item in billType" :label="item.name" :value="item.id" :key="item.id"></el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="业务系统编号：">
				  <el-input v-model.trim="ruleForm.requestCode"></el-input>
				</el-form-item>

				<el-form-item label="推送编号：">
				  <el-input v-model.trim="ruleForm.pushCode"></el-input>
				</el-form-item>

				<el-form-item label="状态：">
				  <el-select v-model="ruleForm.status">
				    <el-option v-for="item in stateList" :label="item.label" :value="item.id" :key="item.id"></el-option>
				  </el-select>
				</el-form-item>

				<el-form-item label="操作人：">
				  <el-input v-model.trim="ruleForm.name"></el-input>
				</el-form-item>

				<el-form-item label="操作时间" prop="time">
				  <el-date-picker
				    v-model="ruleForm.time"
				    type="datetimerange"
				    range-separator="至"
				    start-placeholder="开始日期"
				    end-placeholder="结束日期"
				    :picker-options="pickerOptions"
				    @change="changeDate"
				  >
				  </el-date-picker>
				</el-form-item>

	            <el-form-item>
	            	<el-button type="primary"  @click="searchList" id="monitorEnter">查询</el-button>
	            	<el-button type="primary"  @click="pushhander">推送</el-button>
	            </el-form-item>
			</el-form>

			<el-table :data="tableData" border  style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="55" align="center" :selectable='checkboxT'></el-table-column>
				<el-table-column type="index" label="序号" width="50" align="center" fixed></el-table-column>
				<el-table-column  align="center" prop="typeText" label="推送类型" width="160"></el-table-column>
				<el-table-column align="center" prop="requestCode" label="系统业务编号" width="180"></el-table-column>
				<el-table-column align="center" prop="subjectName" label="业务系统科目名称" width="190"></el-table-column>
				<el-table-column align="center" prop="billTypeName" label="单据类型" width="160"></el-table-column>
				<el-table-column align="center" prop="cityName" label="城市"></el-table-column>
				<el-table-column align="center" prop="devName" label="楼盘名称"  width="150"></el-table-column>
				<el-table-column align="center" prop="amount" label="含税金额" width="160" :formatter="initCash"></el-table-column>
				<el-table-column align="center" prop="payMethod" label="支付方式" width="160">
					<template slot-scope="scope">{{["现金","购物卡"][scope.row.payMethod]}}</template>
				</el-table-column>
				<el-table-column align="center" prop="noTaxAmount" label="不含税金额" width="160" :formatter="initCash"></el-table-column>
			<!-- 	<el-table-column align="center" prop="taxRate" :formatter="initTaxRate" label="税率"></el-table-column> -->
				<el-table-column align="center" prop="taxRateShow" label="税率"></el-table-column>
				<el-table-column align="center" prop="taxAmount" label="税额"></el-table-column>
				<el-table-column align="center" prop="note" label="备注" width="150"></el-table-column>
				<el-table-column align="center" prop="targetName" label="人员/公司信息" width="160"></el-table-column>
				<el-table-column align="center" prop="customerMerchant" label="客商" width="160"></el-table-column>
				<el-table-column align="center" prop="recBankName" label="开户行" width="170"></el-table-column>
				<el-table-column align="center" prop="recAccNo" label="账号" width="175"></el-table-column>

				<el-table-column align="center" prop="amount" label="金额" width="160" :formatter="initCash"></el-table-column>
				<el-table-column align="center" prop="batchCode"  label="金蝶推送批次号" width="180"></el-table-column>
				<el-table-column align="center" prop="pushCode"  label="推送编号" width="200"></el-table-column>
				<el-table-column align="center" label="时间" width="160">
				 <template slot-scope="scope">
				   <TimeComp :timestamp="scope.row.updateTime"></TimeComp>
				 </template>
				</el-table-column>
				<el-table-column align="center" prop="userName" label="操作人" width="150"></el-table-column>
				<el-table-column align="center" label="状态" width="100">
				 <template slot-scope="scope">
				   {{scope.row.status == 1?"成功":"失败"}}
				 </template>
				</el-table-column>
				<el-table-column align="center" label="操作" width="140" fixed='right'>
				 <template slot-scope='scope'>
                     <el-button type="text" @click="btnhander('push',scope.row)" :disabled="scope.row.status == 1">推送</el-button>
                     <el-button type="text" @click="btnhander('rePush',scope.row)">重新推送影像</el-button>
                     <!--<el-button type="text" @click="btnhander('logview',scope.row)">日志查看</el-button>-->
                 </template>
				</el-table-column>
			 </el-table>
			 <div class="pagebar">
			   <el-pagination
			     background
			     layout="total, sizes, prev, pager, next"
			     :current-page.sync="ruleForm.pageNum"
			     :page-sizes="[10, 20, 30, 40]"
			     :page-size="ruleForm.pageSize"
			     @size-change="handleSizeChange"
			     @current-change="handleCurrentChange"
			     :total="totalSize">
			   </el-pagination>
			 </div>
		</div>
		<!-- 弹出框 -->
<!-- 		<el-dialog
		  title="日志查看"
		  :visible.sync="dialogVisible"
		  width="50%"
		  center>
		  	<el-form>
		  		<ul class="see-dialog">
		  			<li class="item itemwidth100">批次号: {{findidData.batchCode}}</li>
		  			<li class="item itemwidth50">编号: {{findidData.pushCode}}</li>
		  			<li class="item itemwidth50 dline">推送时间: <TimeComp :timestamp="findidData.updateTime"></TimeComp>
		  			</li>
		  			<li class="item itemwidth50" v-show="pType == 1 || pType == 2 || pType == 3 || pType == 4 || pType == 5">城市: {{findidData.cityName}}</li>
		  			<li class="item itemwidth50" v-show="pType == 1 || pType == 2 || pType == 3 || pType == 4 || pType == 5">楼盘名称: {{findidData.devName}}</li>
		  			<li class="item itemwidth50"  v-show="pType == 1 || pType == 2 ">金额: {{findidData.amount | initcaseF}}</li>
		  		    <li class="item itemwidth100"  v-show="pType == 1 || pType == 2  && findidData.targetName">备注:  {{findidData.targetName}}</li>
		  			<li class="item itemwidth50" v-show="pType == 3">本次回款金额:{{findidData.amount | initcaseF}}</li>
		  			<li class="item itemwidth50" v-show="pType == 4">实际收款金额:{{findidData.amount | initcaseF}}</li>
		  			<li class="item itemwidth50" v-show="pType == 5 || pType == 6">收款人姓名: {{findidData.targetName}}</li>
		  			<li class="item itemwidth50" v-show="pType == 6">证件号码: {{findidData.idCard}}</li>
		  			<li class="item itemwidth50" v-show="pType == 6">开户支行: {{findidData.recSubBankName}}</li>
		  			<li class="item itemwidth50" v-show="pType == 7">公司名称: {{findidData.targetName}}</li>
		  			<li class="item itemwidth50" v-show="pType == 7">申请结佣金额: {{findidData.amount | initcaseF}}</li>
		  			<li class="item itemwidth50" v-show="pType == 5 || pType == 6 || pType == 7">开户行: {{findidData.recBankName}}</li>
		  			<li class="item itemwidth50" v-show="pType == 5 || pType == 6 || pType == 7" >银行账号: {{findidData.recAccNo}}</li>
		  			<li class="item itemwidth50" v-show="pType == 5">退款金额:{{findidData.amount | initcaseF}}</li>
		  			<li class="item itemwidth100" v-show="pType == 5">退款理由: {{findidData.extend}}</li>
		  			<li class="item itemwidth50" v-show="pType == 6">应付款金额: {{findidData.amount | initcaseF}}</li>
		  		</ul>
		  	</el-form>
			<span slot="footer" class="dialog-footer">
			    <el-button type="primary" @click="dialogVisible = !dialogVisible">关闭</el-button>
			</span>
		</el-dialog> -->
	</div>
</template>
<script>
	import TimeComp from '../common/timeComp'
	import api from '@/api/apiPath'
	export default {
		name:'jindieManage',
		title:'金蝶推送管理',
		components:{TimeComp},
		data () {
			return {
				multipleSelection: [],
				pType: undefined,//推送类型 1 交易及佣金 2交易及佣金驳回 3 回款 4 支付 5退款 6 网络推客 7经纪人结佣
				// dialogVisible: false,
				tableData: [],//列表数据
				// findidData:[],//查看数据
				citys:[],
				ruleForm:{
					cityCode:undefined,
					pushType:"",//推送类型
					status:undefined,//状态 1成功 2失败
					startTime:'',//开始时间
					endTime:'', //结束时间
					time:[],//发布时间
					name:undefined,//操作人
                    subjectCode:'',//业务系统科目名称
                    billTypeCode:'',//单据类型
					requestCode:undefined,//业务系统编号
					pushCode:undefined,//推送编号
					pageNum: 0,
					pageSize: 10,
				},
				typeList: [],
				stateList: [
				  {id: undefined, label: '全部'},
				  {id: 1, label: '成功'},
				  {id: 2, label: '失败'},
				],
				subjectName:[],
				billType:[],
				totalSize:0,
				pickerOptions: {
				  disabledDate(time) {
				     return time.getTime() > Date.now() - 8.64e6;
				  }
				}
			}
		},
		methods:{
			checkboxT(row,index){
				if (row.status == 1) {
					return false
				}else{
					return true
				}
			},
			//批量推送
			pushhander(){
				const pushCode = this.multipleSelection.map(item => item.pushCode)
				if (pushCode.length<1) { return}
				this.axios.post(api.KINGDEEBATCHPUSH,{pushCodes:pushCode}).then(res => {
					if (res.data.code == 200) {
						let str = ''
						res.data.data.forEach(item => str+=`<p>推送编号:${item.pushCode}, ${item.msg} </p>` )
						this.$alert(str, '提示', {
						          confirmButtonText: '确定',
						          dangerouslyUseHTMLString: true,
						          center: true,
						          callback: action => {
						          	this.ruleForm.status = undefined
						            this.getlist()
						          }
						});
					}else {
						this.$message.error(res.data.msg)
					}
				})

			},
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},
			pushTypeF(row, column, cellValue, index){
				if (cellValue == 1) {
					return '交易及佣金'
				}else if(cellValue == 2){
					return '交易及佣金驳回'
				}else if(cellValue == 3){
					return '回款'
				}else if(cellValue == 4){
					return '支付信息'
				}else if (cellValue == 5){
					return '退款信息'
				}else if(cellValue == 6){
					return '网络推客结佣'
				}else if(cellValue == 7){
					return '经纪公司结佣'
				}else if(cellValue == 8){
					return '经纪人结佣'
				}
			},
			loadCity(){
				this.axios.post(api.CITYLIST).then(res => {
					if (res.data.code !== 200) {
						this.$message(res.data.msg)
					}else {
						this.citys = res.data.data.cityList
					}
				})
			},
			getFloat(number, n) {
				n = n ? parseInt(n) : 0;
				if(n <= 0) {
					return Math.round(number);
				}
				number = Math.round(number * Math.pow(10, n)) / Math.pow(10, n); //四舍五入
				number = Number(number).toFixed(n); //补足位数
				return number + '%';
			},

			initTaxRate(row, column, cellValue, index){
				if (!cellValue)  return
					let temp = cellValue*100
					return this.getFloat(temp,2)
			},
			initCash(row, column, cellValue, index){
				if (!cellValue)  return
			    if(cellValue != ""){
			        return cellValue.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");
			    }
			    if(cellValue == 0){
			        return "0.00"
			    }
			},
			//查询时间
			changeDate (val) {
				const startTime1 = val ? val[0] : ''
				this.ruleForm.startTime = startTime1 ? new Date(startTime1).getTime() : undefined
				const endTime1 = val ? val[1] : ''
				this.ruleForm.endTime = endTime1 ? new Date(endTime1).getTime() : undefined
			},
			searchList(){
				this.ruleForm.pageNum = 1;
				this.getlist();
			},
			//推送
			btnhander(type, row){
				if (type === 'push') {
					this.axios.post(api.KINGDEEPUSH,{pushCode:row.pushCode}).then(res => {
						if (res.data.code == 200) {
							this.$message.success('推送成功');
							this.getlist()
						}else {
							this.$message.error(res.data.msg)
						}
					})
				}
				// else if(type === 'logview'){
				// 	this.pType = row.type
				// 	this.dialogVisible = true
				// 	this.axios.post(api.KINGDEEFIND,{id:row.id}).then(res => {
				// 		if (res.data.code == 200) {
				// 			this.findidData = []
				// 			this.findidData = res.data.data
				// 		}else {
				// 			this.$message.error(res.data.msg)
				// 		}
				// 	})
				// }
				else if(type=='rePush'){
                    this.axios.post(api.KINGDEEREPUSH,{batchNum:row.batchCode}).then(res => {
                        if (res.data.code == 200) {
                            this.$message.success('推送成功');
                            this.getlist()
                        }else {
                            this.$message.error(res.data.msg)
                        }
                    })
                }
			},
			getlist(){
				if (this.ruleForm.endTime !== '') {
					this.ruleForm.endTime = Number(this.ruleForm.endTime) + 8.64e7
				}
				this.axios.post(api.KINGDEELIST,this.ruleForm).then(res => {
					if (res.data.code !== 200) {
						this.$message(res.data.msg)
					}else {
						this.tableData = res.data.data.list
						this.totalSize = res.data.data.total
					}
				})
			},
			handleCurrentChange(){
				this.getlist()
			},
			handleSizeChange(val){
				this.ruleForm.pageSize = val
				this.getlist();
			},
            kingdeeQueryOptions(){
                this.axios.post(api.kingdeeQueryOptions, {
                    type: 1,
                }).then((res) => {
                    this.subjectName = res.data.data;
                });
                this.axios.post(api.kingdeeQueryOptions, {
                    type: 2,
                }).then((res) => {
                    this.billType = res.data.data;
                });
                this.axios.post(api.kingdeeQueryOptions, {
                    type: 3,
                }).then((res) => {
                    this.typeList = res.data.data;
                })
			}

		},
		activated(){
			this.searchList()
		},
		created () {
		    this.kingdeeQueryOptions();
			this.loadCity()
			this.getlist()
		},
		filters:{
			initcaseF(val){
				let num = Number(val)
				return num.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");
			}
		}
	}

	</script>
	<style lang="stylus">
	.jindieWrapper ul, li {
		padding: 0;
		margin: 0;
		list-style: none;
	}
	.jindieWrapper .el-dialog__header {
		border-bottom: 1px solid rgba(7, 17, 27, .1)
	}
	.jindieWrapper .see-dialog {
		overflow: hidden;
	}
	.jindieWrapper .see-dialog .item {
		float: left;
		margin: 5px 0;
	}
	.jindieWrapper .see-dialog .itemwidth50 {
		width: 50%;
	}
	.jindieWrapper .see-dialog .itemwidth100 {
		width: 100%;
	}
	.jindieWrapper .dline > div{
		display: inline-block;
	}
   .el-message-box{
   		width:480px !important;
   	}

</style>
